import 'package:flutter/material.dart';

class ListItem extends StatelessWidget {
  final dynamic title;
  final dynamic image;
  final dynamic viewCount;
  static double ITEM_HEIGHT = 100;
  static double TITLE_HEIGHT = 80;
  static double MARGIN_SIZE = 10;
  const ListItem(
      {Key? key,
      required this.title,
      required this.image,
      required this.viewCount})
      : super(key: key);

  Widget _imageWrapper(String image) {
    return SizedBox(
      width: 150,
      height: ITEM_HEIGHT,
      child: Image.network(image),
    );
  }

  Widget _titleWrapper(BuildContext context, String title) {
    return Container(
      height: TITLE_HEIGHT,
      margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
      padding:EdgeInsets.fromLTRB(10, 0, 0, 0),
      child: Text(
        this.title,
        maxLines: 2,
        overflow: TextOverflow.ellipsis,
        style: TextStyle(
          color:Colors.black,
          fontSize: 16.0
        ),
      ),
    );
  }

  Widget _viewCountWrapper(int viewCount) {
    return Container(
      margin: EdgeInsets.fromLTRB(MARGIN_SIZE, 0, 0, 0),
      height: ITEM_HEIGHT - TITLE_HEIGHT,
      child: Row(
        children: [
          Icon(Icons.remove_red_eye_outlined, size: 14.0, color: Colors.grey),
          SizedBox(width: 5),
          Text(
            this.viewCount.toString(),
            style: TextStyle(color: Colors.grey, fontSize: 12.0),
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(MARGIN_SIZE),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _imageWrapper(image),
          Expanded(
              child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              _titleWrapper(context, title),
              _viewCountWrapper(viewCount)
            ],
          ))
        ],
      ),
    );
  }
}
